<template>
	<view class="box">
		<view class="reg-card" v-for="item in register"
			v-show="getDaysBetweenDates(item.visitTime) >= 0 && item.payStatus == 3">
			<view class="between">
				<view class="flex-1">
					<view class="flex-start center">
						<view>
							<image class="img-head" v-if="item.doctorHead" :src="hostApi+item.doctorHead"></image>
							<image class="img-head" v-else src="/static/images/hospital/defaultDoctor.png"></image>
						</view>
						<view>
							<view>
								<view class="doctor-name">{{item.doctorName}}</view>
								<view class="job start-center">
									<view class="job-title">{{item.jobTitle}}</view>
									<view class="border-left"></view>
									<view class="department-name">{{item.departmentName}}</view>
								</view>
							</view>

						</view>
					</view>
					<view class="campus start-center">
						<view v-if="hospital.level">{{hospital.level}}</view>
						<view class="mar-0-5" v-if="hospital.level">{{hospital.name}}</view>
						<view v-else>{{hospital.name}}</view>
					</view>
				</view>
				<view class="btn">
					<view class="flex-end">
						<view class="countdown">
							{{getDaysBetweenDates(item.visitTime) > 0 ? `${getDaysBetweenDates(item.visitTime)}天后就诊` : '今日就诊'}}
						</view>
					</view>
					<view class="btn-guidance" @click="toAss(item)">
					</view>
				</view>
			</view>
			<view class="border-row"></view>
			<view class="address">
				<view class="start-center">
					<image class="img-address" src="/static/images/imgs/clock.png"></image>
					<view>{{item.visitTime}} {{item.visitArea}}</view>
				</view>
				<view class="start-center">
					<image class="img-address" src="/static/images/imgs/nav.png"></image>
					<view class="department-address">{{item.departmentAddress}}</view>
				</view>
			</view>
			<!-- <view class="top flexR">
				<view class="">
					【{{item.campusName}}】
				</view>
				<view class="countdown">
					{{getDaysBetweenDates(item.visitTime) > 0 ? `${getDaysBetweenDates(item.visitTime)}天后就诊` : '今日就诊'}}
				</view>
			</view>
			<view class="content">
				<view class="">
					{{item.visitTime}} {{getWeekDay(item.visitTime)}}
				</view>
				<view class="">
					{{item.departmentName}}--{{item.doctorName}}({{item.jobTitle}})
				</view>

				<view class="btn" @click="toAss(item)">
					查看您的就医指引
				</view>

				<view class="" style="font-size: 24upx;">
					候诊·交费·取药·检查检验·报告·评价
				</view>
			</view> -->
		</view>
	</view>
</template>

<script>
	import dayjs from 'dayjs'
	import {
		mapGetters,
	} from 'vuex';
	export default {
		props: {
			register: Array
		},
		data() {
			return {
				hospital: {}
			}
		},

		computed: {
			...mapGetters([
				'userInfo', 'hostApi', "hospitalInfo"
			])
		},
		mounted() {
			this.init();
		},
		methods: {
			init() {
				this.hospital = this.hospitalInfo.find(item => item.code == this.userInfo.campusCode);
				if (!this.hospital) {
					this.hospital = this.hospitalInfo[0]
				}
				console.log(this.hospital)
			},
			getDaysBetweenDates(targetDate) {
				// 获取目标日期的时间戳
				const targetTimestamp = new Date(targetDate).getTime();

				// 获取当前日期的时间戳
				const currentTimestamp = new Date().getTime();

				// 计算时间差（毫秒）
				const diffMilliseconds = targetTimestamp - currentTimestamp;

				// 将时间差转换为天数
				const days = Math.ceil(diffMilliseconds / (1000 * 60 * 60 * 24));

				return days;
			},
			getWeekDay(dateString) {
				const date = new Date(dateString);
				const dayOfWeek = date.getDay();
				const weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
				return weekDays[dayOfWeek];
			},
			toAss(item) {
				// file: ///G:/project/mk/web/internethospital/pages/Home/ServePatient/MedicalGuidance.vue
				uni.navigateTo({
					url: `/pages/Home/ServePatient/MedicalGuidance?item=` + JSON.stringify(item)
				})
				// this.$emit('toMedicalAssistant')
			}

		}
	}
</script>

<style lang="scss" scoped>
	.reg-card {
		border-radius: 10px;
		background-color: #F3FAFF;
		margin: 16rpx 0;

		.img-head {
			height: 38px;
			width: 38px;
			border-radius: 50%;
			margin: 10px;
		}

		.doctor-name {
			height: 15px;
			font-family: AlibabaPuHuiTi, AlibabaPuHuiTi;
			font-weight: 400;
			font-size: 16px;
			color: #0E282B;
			line-height: 15px;
			text-align: left;
			font-style: normal;
			text-transform: none;
		}


		.job {
			height: 15px;
			font-family: AlibabaPuHuiTi, AlibabaPuHuiTi;
			font-weight: 400;
			font-size: 13px;
			color: #666666;
			line-height: 15px;
			text-align: left;
			font-style: normal;
			text-transform: none;
			margin-top: 16rpx;

		}

		.job-title {
			width: 80px;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}

		.campus {
			margin-top: -5px;
			margin-left: 58px;
			height: 15px;
			font-family: AlibabaPuHuiTi, AlibabaPuHuiTi;
			font-weight: 400;
			font-size: 12px;
			color: #999999;
			line-height: 15px;
			text-align: left;
			font-style: normal;
			text-transform: none;
		}

		.border-left {
			border-left: 1px solid rgb(209, 219, 226);
			margin: 10px;
			height: 10px;
			width: 0px;
		}

		.border-row {
			border-bottom: 1px solid rgb(209, 219, 226);
			margin: 10px;
		}

		.department-name {
			width: 120px;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;

		}

		.btn {
			.countdown {
				background-image: url($mk-base+"/static/images/imgs/bg-yellow.png");
				background-repeat: no-repeat;
				background-size: 100% 100%;
				color: white;
				white-space: nowrap;
				border-radius: 0 10px 0 10px;
				font-family: AlibabaPuHuiTi, AlibabaPuHuiTi;
				font-weight: 400;
				font-size: 11px;
				color: #FFFFFF;
				text-align: center;
				font-style: normal;
				text-transform: none;
				width: 90px;
			}

			.btn-guidance {
				width: 66px;
				height: 22px;
				margin: 20px 16px 0 0;
				background-image: url($mk-base+"/static/images/imgs/jiuyizhushou.png");
				background-repeat: no-repeat;
				background-size: 100% 100%;
			}

		}


		.img-address {
			height: 16px;
			width: 16px;
		}

		.address {
			font-size: 12px;
			color: #2E6D78;
			display: flex;
			justify-content: space-between;
			padding: 0 10px 10px 10px;
			width: 100%;

			.department-address {
				width: 300rpx;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}
		}
	}
</style>